package guowei.guliproduct.product.web;

import guowei.common.utils.R;
import guowei.common.vo.MemberVo;
import guowei.guliproduct.product.entity.CategoryEntity;
import guowei.guliproduct.product.service.CategoryService;
import guowei.guliproduct.product.vo.CateLogErSan;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

/**
 * thymeleaf渲染，用的是javaweb那一套
 */
@Controller
public class CategoryOnes {

    @Autowired
    private CategoryService categoryService;

    /**
     * 跳转首页
     * @param model
     * @return
     */
    @GetMapping({"/","/index","index.html"})
    public String getCategoryOnes(Model model, HttpSession session){
        List<CategoryEntity> categoryOnes = categoryService.selectAllOnes();
        model.addAttribute("categoryones",categoryOnes);
        return "index";
    }

    /**
     * 处理二级和三级分类的请求
     */
    @GetMapping("/index/catalog.json")
    @ResponseBody
    public Map<String,List<CateLogErSan>> getErSan(){
        Map<String,List<CateLogErSan>> map = categoryService.getYiErSan();
        return map;
    }

    /**
     * 获取所有一级分类
     */
    @ResponseBody
    @GetMapping("/yiji")
    public R getyiji(){
        List<CategoryEntity> lists = categoryService.getyi();
        return R.ok().put("data",lists);
    }
}
